//
//  HWPanHangBangAllTableViewCell.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/17.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWPanHangBangAllTableViewCell.h"

@implementation HWPanHangBangAllTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
        [self setupUI];
    }
    
    
    return self;
    
    
}




- (void)setupUI {
    
    self.rankingImageView  = [[UIImageView alloc]initWithFrame:CGRectMake(12, 21, 27, 30)];
    self.rankingImageView.image = [UIImage imageNamed:@"panhangbandiyiming"];
    [self.contentView addSubview:self.rankingImageView];
    
    
    self.icoIamgeView  = [[UIImageView alloc]initWithFrame:CGRectMake(49, 8, 55, 55)];
    self.icoIamgeView.image = [UIImage imageNamed:@"ceshiyongdeyouxitupian"];
    self.icoIamgeView.layer.cornerRadius = 8;
    self.icoIamgeView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.icoIamgeView];
    
    
    self.mingchengLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.icoIamgeView.right+10, 12, 200, 14)];
    self.mingchengLabel.text = @"神雕侠侣2";
    self.mingchengLabel.textColor = RGB(51, 51, 51);
    self.mingchengLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.mingchengLabel];
    
    self.daxiaoLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.icoIamgeView.right+10,  self.mingchengLabel.bottom+6, 40, 10)];
    self.daxiaoLabel.text = @"500M";
    self.daxiaoLabel.textColor = RGB(130, 130 , 130);
    self.daxiaoLabel.font = [UIFont systemFontOfSize:11];
  //  self.daxiaoLabel.backgroundColor = [UIColor redColor];
    
    [self.contentView addSubview:self.daxiaoLabel ];
    
    
    self.downloadNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.daxiaoLabel.right+2,  self.mingchengLabel.bottom+6, 300, 10)];
    self.downloadNumberLabel.text = @"| 角色 动作 836次下载";
    self.downloadNumberLabel.textColor = RGB(130, 130 , 130);
    self.downloadNumberLabel.font = [UIFont systemFontOfSize:11];
  //  self.downloadNumberLabel.backgroundColor = [UIColor redColor];
    
    [self.contentView addSubview:self.downloadNumberLabel];
    
    self.libaoBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.libaoBut.frame = CGRectMake(self.icoIamgeView.right+10, self.downloadNumberLabel.bottom+6, 35, 12);
    [self.libaoBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.libaoBut.backgroundColor = RGB(253, 178, 50);
    self.libaoBut.titleLabel.font = [UIFont systemFontOfSize:9];
    [self.libaoBut setTitle:@"礼包" forState:UIControlStateNormal];
    self.libaoBut.layer.cornerRadius = 3;
    self.libaoBut.layer.masksToBounds = YES;
    [self.contentView addSubview:self.libaoBut];
    
    
    self.maiVBVBan = [UIButton buttonWithType:UIButtonTypeCustom];
    self.maiVBVBan.frame = CGRectMake(self.libaoBut.right+5, self.downloadNumberLabel.bottom+6, 35, 12);
    [self.maiVBVBan setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.maiVBVBan.backgroundColor = RGB(254, 83, 37);
    self.maiVBVBan.titleLabel.font = [UIFont systemFontOfSize:9];
    [self.maiVBVBan setTitle:@"满V版" forState:UIControlStateNormal];
    self.maiVBVBan.layer.cornerRadius = 3;
    self.maiVBVBan.layer.masksToBounds = YES;
    [self.contentView addSubview:self.maiVBVBan];
    
    
    self.chongzhiBan = [UIButton buttonWithType:UIButtonTypeCustom];
    self.chongzhiBan.frame = CGRectMake(self.maiVBVBan.right+5, self.downloadNumberLabel.bottom+6, 60, 12);
    [self.chongzhiBan setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.chongzhiBan.backgroundColor = RGB(45, 179, 57);
    self.chongzhiBan.titleLabel.font = [UIFont systemFontOfSize:9];
    [self.chongzhiBan setTitle:@"充值1:50 送vip" forState:UIControlStateNormal];
    self.chongzhiBan.layer.cornerRadius = 3;
    self.chongzhiBan.layer.masksToBounds = YES;
    [self.contentView addSubview:self.chongzhiBan];
    
    
    self.chaKanBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.chaKanBut.frame = CGRectMake(kScreenW-50-15, 28, 50, 25);
    self.chaKanBut.backgroundColor = blueBackgroundBT;
    self.chaKanBut.titleLabel.font = [UIFont systemFontOfSize:13];
    
    NSString *chakan =   [HWjianzhiduiObject keylocalization:@"查看"];
    [self.chaKanBut setTitle:@"查看" forState:UIControlStateNormal];
    [self.chaKanBut setTitle:chakan forState:UIControlStateNormal];
    self.chaKanBut.userInteractionEnabled = NO;
    self.chaKanBut.layer.cornerRadius = 12;
    self.chaKanBut.layer.masksToBounds = YES;
    [self.contentView addSubview:self.chaKanBut];
    
    
      self.jiluLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,  0, 49, 71)];
      self.jiluLabel.text = @"1";
      self.jiluLabel.textColor = RGB(51, 51 , 51);
      self.jiluLabel.font = [UIFont systemFontOfSize:12];
    //  self.downloadNumberLabel.backgroundColor = [UIColor redColor];
      self.jiluLabel.textAlignment  = NSTextAlignmentCenter;
      [self.contentView addSubview:self.jiluLabel];
    
    
//    self.mingchengLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.icoIamgeView.right+10, 12, 200, 14)];
    [self.mingchengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icoIamgeView.mas_right).offset(10);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(14);
    }];
    
    self.onSaleLabel = [[UILabel alloc] init];
    self.onSaleLabel.font = [UIFont systemFontOfSize:10];
    self.onSaleLabel.textColor = UIColor.whiteColor;
    self.onSaleLabel.backgroundColor = UIColor.redColor;
    self.onSaleLabel.layer.cornerRadius = 3;
    self.onSaleLabel.layer.masksToBounds = YES;
    [self.contentView addSubview:self.onSaleLabel];
    
    self.onSaleLabel.hidden = YES;
    [self.onSaleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mingchengLabel.mas_right).offset(10);
        make.height.mas_equalTo(13);
        make.centerY.mas_equalTo(self.mingchengLabel);
        make.right.mas_lessThanOrEqualTo(-15);
//        make.centerX.mas_equalTo(self.chaKanBut);
    }];
    [self.onSaleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
}

- (void)setDataModel:(HWPaiHangModel *)dataModel {
    
    _dataModel = dataModel;
    NSURL *url = [NSURL URLWithString:dataModel.icon];
    [self.icoIamgeView sd_setImageWithURL:url placeholderImage:nil];
    
    self.mingchengLabel.text = [NSString stringWithFormat:@"%@",dataModel.name];
    
    self.daxiaoLabel.text = [NSString stringWithFormat:@"%@",dataModel.size];
    // @"| 角色 动作 836次下载";
    self.downloadNumberLabel.text = [NSString stringWithFormat:@"| %@ %@",dataModel.type,dataModel.number];
    
    if (dataModel.biaoqian.count > 0 ) {
        
        for (int i = 0; i < dataModel.biaoqian.count ; i++) {
            if (i == 0) {
                 [self.libaoBut setTitle:dataModel.biaoqian[i] forState:UIControlStateNormal];
            } else if (i == 1) {
                [self.maiVBVBan setTitle:dataModel.biaoqian[i] forState:UIControlStateNormal];
                
            } else if (i == 2) {
                
                [self.chongzhiBan setTitle:dataModel.biaoqian[i] forState:UIControlStateNormal];
            }
            
        }
       
     
       // [self.libaoBut setTitle:@"礼包" forState:UIControlStateNormal];
        
    }
    
    
    if (dataModel.zhekou.length > 0) {
        self.onSaleLabel.hidden = NO;
        if ([dataModel.zhekou containsString:@"折"]) {
            self.onSaleLabel.text = [NSString stringWithFormat:@" %@ ",dataModel.zhekou];
        } else {
            self.onSaleLabel.text = [NSString stringWithFormat:@" %@折 ",dataModel.zhekou];
        }
        
        if ([self.onSaleLabel.text isEqualToString:@" 10折 "]) {
            self.onSaleLabel.hidden = YES;
        }
    } else {
        self.onSaleLabel.hidden = YES;
    }
    
}

@end
